﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-12-17 12:30:06
// 负责人：liucx
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
namespace OF.Component.DAL
{

    /// <summary>
    /// 数据访问层
    /// </summary>	
    internal partial class MessagePool
    {

        /// <summary>
        /// 根据断言条件获取单个
        /// </summary>
        public MessagePoolInfo QuerySingle(Expression<Func<MessagePoolInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取列表
    	/// </summary>
	    public IList<MessagePoolInfo> QueryList(Expression<Func<MessagePoolInfo, bool>> predicate)
        {
            return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
        }

        /// <summary>
        /// 更新消息为已发送
        /// </summary>
        /// <param name="messageStatus">消息状态</param>
        /// <param name="sendDate">发送时间</param>
        /// <param name="errorMsg">错误消息</param>
        /// <param name="userID">用户ID</param>
        /// <param name="messageID">消息ID</param>
        /// <returns></returns>
        public int UpdateMessageSend(int messageStatus, DateTime sendDate, string errorMsg, long userID, long messageID)
        {
            string sqlStr = "UPDATE MessagePool SET IsRead=2,MessageStatus=@MessageStatus,SendDate=@SendDate,ErrorMessage=@ErrorMessage WHERE UserID=@UserID AND MessageID=@MessageID";
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(sqlStr);
            //设置参数
            db.AddInParameter(dbc, "@MessageStatus", DbType.Int32, messageStatus);
            db.AddInParameter(dbc, "@SendDate", DbType.DateTime, sendDate);
            db.AddInParameter(dbc, "@ErrorMessage", DbType.String, errorMsg);
            db.AddInParameter(dbc, "@UserID", DbType.Int64, userID);
            db.AddInParameter(dbc, "@MessageID", DbType.Int64, messageID);
            return db.ExecuteNonQuery(dbc);
        }
    }

}